from core.log import logging
class logic_basic():
    __error_message__=[]
    __result__= None
    __state__= False
    __msg__= None
    
    @property
    def State(self):
        return self.__state__
    
    @property
    def Msg(self):
        return self.__msg__
        
    @Msg.setter
    def Msg(self,v):
        self.__msg__=v
    
    @property
    def Result(self):
        return self.__result__
    
    @property
    def error_message(self):
        m_error_msg=""
        for v in self.__error_message__:
            m_error_msg= "".join([m_error_msg,";\r\n" if m_error_msg else "",v])
        return m_error_msg
    
    @Result.setter
    def Result(self,v):
        self.__result__= v
        if not isinstance(v,bool):    
            if v:
                self.__state__= True
            else:
                self.__state__= False
        else:
            self.__state__= True            
    
    def error_update(self, basic_error: Exception | str, display_error:str='', to_logging= True):
        '''
            append error_message.
            
            Args:

                basic_error: <cls, Exception | str>, logging record.
                
                display_error: <cls, string>, return msg. default '', if it is null, then it is basic_error.
                
                to_logging: <cls, boolen>, save error on log file. default True.
        '''
        if not isinstance(basic_error,(Exception,str)):
            raise TypeError("'basic_error' type error.")
        if display_error:
            if not isinstance(display_error,str):
                raise TypeError("'display_error' type error.")
        if not display_error:
            if isinstance(basic_error, str):
                self.__error_message__.append(basic_error)
            elif isinstance(basic_error,Exception):
                if to_logging:
                    logging.error(basic_error)
                self.__error_message__.append(basic_error.args[1])
            else:
                raise Exception("method logic.error_update 'basic_error' Type error.")
        else:
            self.__error_message__.append(display_error)
        self.Result= None
        return self.State